

local helper=table();

local smd_index=0;

local utils=sys.link_object("utils");//("app:/scripting/library/utils.ewsl");

/*
helper.new_toolbox=function()
{
	return utils.toolbox.create();
};


helper.new_operation=function(name,label)
{	
	return utils.operation.create(name,label);
};
*/

helper.eval=utils.param.fn_eval;


helper.app_find_result_file=function(folder)
{
	if(fs.exists(folder)!=2)
	{
		return nil;
	}
	
	local arr=fs.files(folder);
	local vvv=[];

	for(it in arr)
	{
		if(it.flag&1) continue;
		local fn=it.name;
		if(!fn.end_with(".mxd")) continue;	
		if(fn.find("raw")>=0) continue;
		
		vvv.push(it.name);
	}

	vvv=sort(vvv);

	if(vvv.length()==0)
	{
		return nil;
	}
	
	if(vvv.length()==1||vvv[0].find("_")<0)
	{
		return folder.."/"..vvv[0];
	}
	else
	{
		return folder.."/"..vvv[end];	
	}
};

helper.app_load_folder_result=function(folder)
{
	#import ui;
	#import io;
	#import toolbox;
	
	local fp=toolbox.helper.app_find_result_file(folder);
	if(fp==nil)
	{
		return nil;
	}
	ui.evt["Plugin.ToolBox"].std_execute("set_default_path",fp);
	return io.load_var(fp);
};


return helper;

